package ce.com.cenewbluesdk.bluetooth;


import ce.com.cenewbluesdk.CEBC;

/**
 * Created by Administrator on 2016/11/8 0008.
 */
public abstract class CEBlueToothBase {

    protected int blueConnectState= CEBC.BLUE_DISCONNECT;
    private blueToothConnectStateChangeListen blueStateChangeListen;
    private blueToothReceiptDataListen blueReceiptDataListen;

    /**
     * 蓝牙连接状态改变的接口
     * 主要是通过这个接口将蓝牙状态传送到外面
     * 对应状态参考CEBC 这个类
     */
    public interface blueToothConnectStateChangeListen {
        public void blueToothConnectStateChange(int state);
    }

    /**
     * 这个接口主要使用数据回调的
     */
    public interface blueToothReceiptDataListen {
        /**
         * 接收到蓝牙数据
         *
         * @param bytes
         */
        public void blueToothReceiptData(byte[] bytes);

        /**
         * 数据发送成功
         *
         * @param bytes 这个是发送成功的数据
         */
        public void dataSendSucceed(byte[] bytes);

        /**
         * 数据发送失败
         *
         * @param bytes
         */
        public void dataSendFailed(byte[] bytes);


    }

    public abstract void  connect(String mac);

    public abstract void disConnect();

    /**
     * 发送数据
     * @param bytes
     */
    public abstract void sendData(byte[] bytes);

    /**
     * 指定通道发送数据
     * @param index
     * @param bytes
     */
    public abstract void sendData(int index,byte[] bytes);

    public void setBlueStateChangeListen(blueToothConnectStateChangeListen blueStateChangeListen) {
        this.blueStateChangeListen = blueStateChangeListen;
    }

    public void setBlueReceiptDataListen(blueToothReceiptDataListen blueReceiptDataListen) {
        this.blueReceiptDataListen = blueReceiptDataListen;
    }

    public void dataSendSucceed(byte [] bytes) {
        if (blueReceiptDataListen != null) {
            blueReceiptDataListen.dataSendSucceed(bytes);
        }
    }
    public void blueToothReceiptDate(byte[] bytes) {
        if (blueReceiptDataListen != null) {
            blueReceiptDataListen.blueToothReceiptData(bytes);
        }
    }
    public void dataSendFailed(byte[] data) {
        if (blueReceiptDataListen != null) {
            blueReceiptDataListen.dataSendFailed(data);
        }
    }
    public void blueToothConnectStateChange(int connectState) {
        if(blueConnectState!=connectState){
            blueConnectState=connectState;
            if (blueStateChangeListen != null) {
                blueStateChangeListen.blueToothConnectStateChange(connectState);
            }
        }

    }
}
